package xml;

import java.awt.Color;

import javax.xml.bind.annotation.adapters.XmlAdapter;

/**
 * Switches between a java ready {@link java.awt.Color Color} object, and the integer form of the color needed to write to xml.
 * @author mylesc,varunr
 *
 */
public class ColorAdapter extends XmlAdapter<Integer, Color> {
	
	/**
	 * Marshals java Color object into integer form.
	 * @param color a Color object to be converted into xml saveable format.
	 * @return intColor an integer representing the color of the Color object ready to be saved to xml.
	 */
	public Integer marshal(Color color) throws Exception {
		int intColor = color.getRGB();

		return intColor;
	}

	/**
	 * Unmarshals the integer form of a color back into a java Color object.
	 * @param intColor an integer representation of a Color that was saved in an xml file.
	 * @return color a Color object with a color of intColor.
	 */
	public Color unmarshal(Integer intColor) throws Exception { 
		Color color = new Color(intColor);
        
        return color;
	}
}
